package com.hiof.heartrate;

import com.hiof.location.GPSManager;
import com.hiof.overlays.MapPointsManager;
import com.hiof.servercommunication.receive.beans.GeoPoint;
import com.hiof.settings.SettingManager;
import com.hiof.utility.Utility;

import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * User: manish
 * Date: 4/17/12
 * Time: 6:50 PM
 * To change this template use File | Settings | File Templates.
 */
public class SimulatorHearRateManager extends HeartRateManager {
    private static SimulatorHearRateManager instance;
    private double hearRate = 0;
    private static final double HIGH_THRESHOLD = 200;
    private static final double LOW_THRESHOLD = 30;

    public static SimulatorHearRateManager getInstance() {
        if (null == instance) {
            instance = new SimulatorHearRateManager();
        }
        return instance;
    }

    private SimulatorHearRateManager() {
    }

    @Override
    public double getLatestHeartRate() {
        Random rand = new Random();
        int min = 50;
        int max = 200;//TODO: change it to the formula 220-age
        hearRate = (double)(rand.nextInt((max+1) - min) + min);
        onHearRateChanged(hearRate);
        return hearRate;
    }

    @Override
    public HealthStatus getHealthStatus() {
        if(hearRate > HIGH_THRESHOLD)
            return HealthStatus.TOO_HIGH;
        else if (hearRate < LOW_THRESHOLD)
            return HealthStatus.TOO_LOW;
        else
            return HealthStatus.OK;
    }

    @Override
    public void destroy(){
        if (instance != null)
            instance = null;
    }
}
